$(function(){
	
	// Checking for CSS 3D transformation support
	$.support.css3d = supportsCSS3D();
	
	var formContainer = $('#formContainer');
	
	// Listening for clicks on the ribbon links
	$('.flipLink').click(function(e){
		
		formContainer.toggleClass('flipped');
		
		// If there is no CSS3 3D support, simply
		// hide the login form (exposing the recover one)
		if(!$.support.css3d){
			$('#login').toggle();
		}
		e.preventDefault();
	});
	
	formContainer.find('form').submit(function(e){
		e.preventDefault();
	});
	
	function supportsCSS3D() {
		var props = [
			'perspectiveProperty', 'WebkitPerspective', 'MozPerspective'
		], testDom = document.createElement('a');
		  
		for(var i=0; i<props.length; i++){
			if(props[i] in testDom.style){
				return true;
			}
		}
		
		return false;
	}
	
	$("#submit").click(function(){
		var username = $("#login input[type=text]").val();
		var password = $("#login input[type=password]").val();
		if( username == "" || password == ""){
			sweetAlert({
				title : "错误",
				text : "用户名或密码不能为空",
				type : "error",
			});
			
		}else
		$.ajax({
			url: $("base").attr("href") + "admin/loginCheck.do",
			method:"post",
			data:{"username":username,"password":password},
			success:function(data){
				if(data.code == 1000){
					sweetAlert({
						title:"正确",
						text:"登录成功，立刻跳转",
						type:"success",
					});
					window.location.href = $("base").attr("href") + "admin/view-homepage.do";
				}else{
					sweetAlert({
						title : "错误",
						text : "用户名或密码错误",
						type : "error",
					});
				}
			},
			error : function(){
				sweetAlert({
						title : "错误",
						text : "连接服务器失败",
						type : "error",
					});
			}
			
		});
	});
});
